/*
 RLEditRecyclableItemViewController.m
 Date Created: February 20, 2010
 
 Author: Karol Krizka <kkrizka@gmail.com>
 
 Copyright (C) 2010 Green-Power
 
 URL: http://code.google.com/p/green-power
 
 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 3 of the License, or
 (at your option) any later version.
 
 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 
 $Id$
 */

#import "RLEditRecyclableItemViewController.h"

#import "RLStyleFormatter.h"


@implementation RLEditRecyclableItemViewController

@synthesize typeIconView;
@synthesize typeNameLabel;
@synthesize depositValueLabel;

@synthesize totalValueLabel;
@synthesize quantityLabel;

@synthesize plusButton;
@synthesize minusButton;

@synthesize item;

- (RLEditRecyclableItemViewController *)initWithItem:(RLRecyclableItem *)itemArg {
  self=[super init];
  if( self ) {
    item=itemArg;
    [self updateLabels];
    [self updateButtons];
  }
  return self;
}

- (void)viewDidLoad {
  [super viewDidLoad];
  [self updateLabels];
  [self updateButtons];
  
  self.typeIconView.image=[UIImage imageNamed:self.item.typeDescription.icon];
}

- (void)updateLabels {
  self.typeNameLabel.text=self.item.typeDescription.name;
  self.depositValueLabel.text=[RLStyleFormatter formatMonetaryValue:self.item.typeDescription.depositValue];
  self.quantityLabel.text=[NSString stringWithFormat:@"%d",self.item.quantity];
  self.totalValueLabel.text=[RLStyleFormatter formatMonetaryValue:self.item.totalValue];
}

- (void)updateButtons {
  if(self.item.quantity == 0) {
    self.minusButton.enabled=NO;
  } else {
    self.minusButton.enabled=YES;
  }
}

- (IBAction)incrementQuantity {
  self.item.quantity=self.item.quantity+1;
  [self updateLabels];
  [self updateButtons];
}

- (IBAction)decrementQuantity {
  if(self.item.quantity>0) {
    self.item.quantity=self.item.quantity-1;
    [self updateLabels];
    [self updateButtons];
  }
}

/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/

- (void)didReceiveMemoryWarning {
	// Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
	
	// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
	// Release any retained subviews of the main view.
	// e.g. self.myOutlet = nil;
}


- (void)dealloc {
    [super dealloc];
}


@end
